import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:signage/app/routes/app_pages.dart';
import 'package:signage/l10n/l10n.dart';
import 'package:signage/widgets/custom_appbar.dart';

import '../controllers/edit_info_controller.dart';

class EditInfoView extends GetView<EditInfoController> {
  const EditInfoView({super.key});
  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          backgroundColor: const Color(0xFFF3F4F6),
          appBar: CustomAppBar(
            backgroundColor: Colors.white,
            title: AppLocalizations.of(context)!.translate('edit_profile'),
            showBackButton: true,
          ),
          body: ListView(
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
            children: [
              // 个人信息卡片
              Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(12.r),
                ),
                child: Column(
                  children: [
                    ListTile(
                      contentPadding:
                          EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
                      leading: controller.profileController.userInfo.value.avatar != null ?
                      ClipOval(
                        child: Image.network(
                          controller.profileController.userInfo.value.avatar!,
                          width: 48.w,
                          height: 48.w,
                          fit: BoxFit.cover,
                           headers: {
                            'Authorization': 'Bearer ${controller.token.value}',
                          },
                        ),
                      ) :
                      ClipOval(
                        child: Image.asset(
                          'assets/images/default_avatar.png',
                          width: 48.w,
                          height: 48.w,
                          fit: BoxFit.cover,
                        ),
                      ),
                      title: Text(AppLocalizations.of(context)!.translate('avatar')),
                      trailing: const Icon(Icons.chevron_right),
                      onTap: () => controller.showImagePicker(),
                    ),
                    Divider(height: 1, color: Colors.grey[200]),
                    ListTile(
                      contentPadding: EdgeInsets.symmetric(horizontal: 16.w),
                      title: Text(AppLocalizations.of(context)!.translate('nickname')),
                      trailing: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Text(controller.profileController.userInfo.value.name ?? '',
                              style: TextStyle(color: Colors.grey[600],fontSize: 14.sp)),
                          const Icon(Icons.chevron_right),
                        ],
                      ),
                      onTap: () {
                        controller.editName();
                      },
                    ),
                    Divider(height: 1, color: Colors.grey[200]),
                    ListTile(
                      contentPadding: EdgeInsets.symmetric(horizontal: 16.w),
                      title: Text(AppLocalizations.of(context)!.translate('mobile')),
                      trailing: Row(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Text(controller.profileController.userInfo.value.mobile ?? '',
                              style: TextStyle(color: Colors.grey[600],fontSize: 14.sp)),
                          const Icon(Icons.chevron_right),
                        ],
                      ),
                      onTap: () {
                        controller.editMobile();
                      },
                    ),
                  ],
                ),
              ),
              // ... 保持其他功能区代码不变 ...
            ],
          ),
        ));
  }
}
